<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">


      <el-button type="primary" @click="abc(0)">初筛{{ statisticsNum.count0 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain @click="abc(1)">面试{{ statisticsNum.count1 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain plain @click="abc(2)">录用{{ statisticsNum.count2 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <!--      <el-button plain @click="abc(3)" >已录用{{statisticsNum.count3}}人</el-button>&nbsp;&nbsp;&nbsp;-->
      <el-button plain @click="abc(4)">淘汰{{ statisticsNum.count4 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-form-item prop="resumeName">
        <el-input
          v-model="queryParams.query"
          placeholder="请输入简历名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-date-picker
          v-model="value2"
          type="daterange"
          value-format="yyyy-MM-dd"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions">
        </el-date-picker> &nbsp;
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-s-promotion"
                size="mini"
                :disabled="multiple"
                @click="handleUpdate()"
                v-hasPermi="['system:auitvo:edit']"
              >推送
              </el-button>

            </el-col>


      &lt;!&ndash;      <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDeletes()"
                v-hasPermi="['system:auitvo:updateIsFirst']"
              >面试不通过</el-button>
            </el-col>&ndash;&gt;

            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['system:auitvo:export']"
              >导出</el-button>
            </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--淘汰弹出框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <span>淘汰原因：</span>
      <template>
        <el-select v-model="soeliminate" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleDeletes()">确 定</el-button>
  </span>
    </el-dialog>

    <el-table v-loading="loading" :data="auitvoList" @selection-change="handleSelectionChange"
              style="width: 100%" max-height="100%">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="候选人名称" align="center" prop="resumeName" width="100"/>
      <el-table-column label="电话" align="center" prop="phone" width="180"/>
      <el-table-column label="岗位类型" align="center" prop="stationCategory" width="180"/>
      <el-table-column label="应聘职位" align="center" prop="stationName" width="180"/>
     <!-- <el-table-column label="企业名称" align="center" prop="companyName" width="250"/>-->
      <el-table-column label="负责招聘" align="center" prop="createName" width="100"/>
      <el-table-column label="状态" align="center" prop="isFirst">
        <template slot-scope="scope">
          <span v-if="scope.row.isFirst == 0">
           待初筛
          </span>
          <span v-if="scope.row.isFirst == 1">
           待面试
          </span>
          <span v-if="scope.row.isFirst == 2">
           待入职
          </span>
          <span v-if="scope.row.isFirst == 3">
           已入职
          </span>
        </template>


      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row.id,scope.row.resumeId)"
            v-hasPermi="['system:auitvo:edit']"
          >通过初筛
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="dialog(scope.row.id,scope.row.resumeId,scope.row.isFirst),dialogVisible = true"
          >淘汰
          </el-button>
          <!--          <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleDeletes(scope.row.id,scope.row.resumeId)"
                      v-hasPermi="['system:auitvo:updateIsFirst']"
                    >面试不通过</el-button>-->
          <!--          <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="downloadFile(scope.row.imgPath)"
                      v-hasPermi="['system:files:download']"
                    >简历下载</el-button>-->

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {updateIsFirst, listAuitvo, addAuitvo, updateAuitvo, statisticsNum} from "@/api/system/auitvo";

  export default {
    name: "Auitvo",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        id: null,
        resumeId: null,
        isFirst: null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        /*淘汰原因*/
        soeliminate: null,
        /*淘汰阶段*/
        ofeliminate: null,
        value2: '',
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        auitvoList: [],
        statisticsNum: {
          count0: 0,
          count1: 0,
          count2: 0,
          count3: 0,
          count4: 0
        },
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        dialogVisible: false,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        options: [{
          value: '',
          label: '请选择'
        }, {
          value: '不符合岗位要求',
          label: '不符合岗位要求'
        }, {
          value: '专业技能欠缺',
          label: '专业技能欠缺'
        }, {
          value: '候选人放弃',
          label: '候选人放弃'
        }, {
          value: '薪资太高',
          label: '薪资太高'
        }, {
          value: '简历不合适',
          label: '简历不合适'
        }],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          isFirst: 0,
          stationSecond: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          query: null,
          beginTime: null,
          endTime: null,
          imgPath: null

        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        resumeIds: []

      };
    },
    created() {
      this.getList();
      this.statistics();
    },
    methods: {
      abc(s) {
        var path = null;
        if (s == 0) {
          path = 'screened'
        }
        if (s == 1) {
          path = 'auitvo'
        }
        if (s == 2) {
          path = 'company'
        }
        if (s == 3) {
          path = 'employed'
        }
        if (s == 4) {
          path = 'obsolete'
        }

        this.$router.push({path: '/resume/auitvo/' + path, query: {}}).catch(() => {
        })
      },
      /** 查询【请填写功能名称】列表 */

      getList() {
        this.loading = true;
        listAuitvo(this.queryParams).then(response => {
          this.auitvoList = response.rows;
          this.total = response.total;
        });
        this.loading = false;
      },
      /** 统计数量 */
      statistics() {
        statisticsNum().then(response => {
          if (response.data !== undefined) {
            this.statisticsNum = response.data;
          }
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.value2 = ''
        this.form = {
          id: null,
          isFirst: 1,
          stationSecond: null,
          createTime: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          imgPath: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {

        if (this.value2 != '' && this.value2 != null) {
          this.queryParams.beginTime = this.value2[0];
          this.queryParams.endTime = this.value2[1];
        }
        if (this.value2 == '' || this.value2 == null) {
          this.queryParams.beginTime = null;
          this.queryParams.endTime = null;
        }

        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.value2 = ''
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          isFirst: 0,
          stationSecond: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          query: null,
          beginTime: null,
          endTime: null,
          imgPath: null
        }
        this.resetForm("queryForm");
        this.handleQuery();
        this.statistics();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {

        this.resumeIds = selection.map(a => a.resumeId)
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      dialog(id, resumeId, isFirst) {
        this.id = id;
        this.resumeId = resumeId;
        this.isFirst = isFirst;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 面试批量通过按钮操作 */
      handleUpdate(id, resumeId) {
        const ids = id || this.ids
        var is_first = 1;
        this.$modal.confirm('是否确认').then(function () {
          return updateAuitvo(ids, is_first, resumeId, null);
        }).then(() => {
          this.getList();
          this.statistics();
          this.$modal.msgSuccess("操作成功");
        }).catch(() => {
        });
      },
      /** 面试批量淘汰 */
      handleDeletes() {
        const ids = this.id || this.ids
        const resumeIds = this.resumeId || this.resumeIds
        var ofeliminate = this.isFirst
        var soeliminate = this.soeliminate
        if (soeliminate == null || soeliminate == '') {
          alert("请输入淘汰原因")
          return;
        }

        this.$modal.confirm('是否确认淘汰').then(function () {
          return updateIsFirst(ids, resumeIds, ofeliminate, soeliminate);
        }).then(() => {
          this.soeliminate = null;
          this.dialogVisible = false;
          this.getList();
          this.statistics();
          this.$modal.msgSuccess("淘汰成功");
        }).catch(() => {
        });
      },
      /** 下载按钮 */
      downloadFile(imgPath) {
        this.$download.previewPdf(imgPath)
      }


      /* /!** 提交按钮 *!/
       submitForm() {
         this.$refs["form"].validate(valid => {
           if (valid) {
             if (this.form.id != null) {
               updateAuitvo(this.form).then(response => {
                 this.$modal.msgSuccess("修改成功");
                 this.open = false;
                 this.getList();
               });
             } else {
               addAuitvo(this.form).then(response => {
                 this.$modal.msgSuccess("新增成功");
                 this.open = false;
                 this.getList();
               });
             }
           }
         });
       }*/

      /* * 导出按钮操作
       handleExport() {
         this.download('system/auitvo/export', {
           ...this.queryParams
         }, `auitvo_${new Date().getTime()}.xlsx`)
       },*/


    }
  };
</script>
